package com.songshu.sca;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.io.IOException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Properties;

@SpringBootApplication(scanBasePackages = "com.songshu.sca")
//@PropertySource(value = "classpath:bootstrap.yml")
public class SpringCloudAlibabaApplication {

    public static void main(String[] args) throws IOException {
        URL resource = ResourceUtil.getResource("bootstrap.yml");
        String s1 = ResourceUtil.readStr("bootstrap.yml", Charset.forName("UTF-8"));
        System.out.println(s1);

//        URL resource1 = ClassLoader.class.getResource("bootstrap.yml");
        URL resource1 = Thread.currentThread().getContextClassLoader().getResource("bootstrap.yml");
//        System.out.println("ssss: " + resource1.toString());
        System.out.println("============================================");
        String s = FileUtil.readString(resource1, Charset.forName("UTF-8"));

        Properties p = new Properties();
        String username = p.getProperty("user.name");
        System.out.println("username: " + username);


        ConfigurableApplicationContext context = SpringApplication.run(SpringCloudAlibabaApplication.class, args);

        ConfigurableEnvironment environment = context.getEnvironment();
        String[] activeProfiles = environment.getActiveProfiles();
        System.out.println("activeProfiles: " + Arrays.toString(activeProfiles));
    }

}
